Append list using iloc[] methods

Pandas DataFrame.iloc method access integer-location based indexing for selection by position. 

Example:

Python3




# import module
import pandas as pd
 
# List
Person = [ ['Satyam', 21, 'Patna' , 'India' ],
            ['Anurag', 23, 'Delhi' , 'India' ],
            ['Shubham', 27, 'Coimbatore' , 'India' ],
            ["Saurabh", 23, "Delhi", "india"]]
 
#Create a DataFrame object
df = pd.DataFrame(Person,
                  columns = ['Name' , 'Age', 'City' , 'Country'])
 
# new list to append into df
list = ['Ujjawal', 22, 'Fathua', 'India']
 
# using iloc
df.iloc[2] = list
 
# display
display(df)


Output:

Note – It is used for location-based indexing so it works for only the existing index and replaces the row element.

How to append a list as a row to a Pandas DataFrame in Python?

Prerequisite: Pandas DataFrame

In this article, We are going to see how to append a list as a row to a pandas dataframe in Python. It can be done in three ways:

Similar Reads

Append list using loc[] methods

Pandas DataFrame.loc attribute access a group of rows and columns by label(s) or a boolean array in the given DataFrame....

Append list using iloc[] methods

...

Append list using append() methods

...